<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The MongoDB\BSON\Binary class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.mongodb.bson-torelaxedextendedjson.html">« MongoDB\BSON\toRelaxedExtendedJSON</a></li>
      <li style="float: right;"><a href="mongodb-bson-binary.construct.html">MongoDB\BSON\Binary::__construct »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.bson.html">MongoDB\BSON</a></li>
    <li>The MongoDB\BSON\Binary class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.mongodb-bson-binary" class="reference">

 <h1 class="title">The MongoDB\BSON\Binary class</h1>
 

 <div class="partintro"><p class="verinfo">(mongodb &gt;=1.0.0)</p>


  <div class="section" id="mongodb-bson-binary.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    BSON type for binary data (i.e. array of bytes). Binary values also have a
    subtype, which is used to indicate what kind of data is in the byte array.
    Subtypes from zero to 127 are predefined or reserved. Subtypes from 128-255
    are user-defined.
   </p>
  </div>


  <div class="section" id="mongodb-bson-binary.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="modifier">final</span>
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">MongoDB\BSON\Binary</strong>
     </span>

     <span class="oointerface"><span class="modifier">implements</span> 
       <a href="class.mongodb-bson-binaryinterface.html" class="interfacename">MongoDB\BSON\BinaryInterface</a></span><span class="oointerface">,  <a href="class.mongodb-bson-type.html" class="interfacename">MongoDB\BSON\Type</a></span><span class="oointerface">,  <a href="class.serializable.html" class="interfacename">Serializable</a></span><span class="oointerface">,  <a href="class.jsonserializable.html" class="interfacename">JsonSerializable</a></span><span class="oointerface">,  <a href="class.stringable.html" class="interfacename">Stringable</a></span> {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-bson-binary.html#mongodb-bson-binary.constants.type-generic"><var class="varname">TYPE_GENERIC</var></a></var><span class="initializer"> = 0</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-bson-binary.html#mongodb-bson-binary.constants.type-function"><var class="varname">TYPE_FUNCTION</var></a></var><span class="initializer"> = 1</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-bson-binary.html#mongodb-bson-binary.constants.type-old-binary"><var class="varname">TYPE_OLD_BINARY</var></a></var><span class="initializer"> = 2</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-bson-binary.html#mongodb-bson-binary.constants.type-old-uuid"><var class="varname">TYPE_OLD_UUID</var></a></var><span class="initializer"> = 3</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-bson-binary.html#mongodb-bson-binary.constants.type-uuid"><var class="varname">TYPE_UUID</var></a></var><span class="initializer"> = 4</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-bson-binary.html#mongodb-bson-binary.constants.type-md5"><var class="varname">TYPE_MD5</var></a></var><span class="initializer"> = 5</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-bson-binary.html#mongodb-bson-binary.constants.type-encrypted"><var class="varname">TYPE_ENCRYPTED</var></a></var><span class="initializer"> = 6</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-bson-binary.html#mongodb-bson-binary.constants.type-column"><var class="varname">TYPE_COLUMN</var></a></var><span class="initializer"> = 7</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-bson-binary.html#mongodb-bson-binary.constants.type-user-defined"><var class="varname">TYPE_USER_DEFINED</var></a></var><span class="initializer"> = 128</span>;</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-binary.construct.html" class="methodname">__construct</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code><span class="initializer"> = MongoDB\BSON\Binary::TYPE_GENERIC</span></span>)</div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-binary.getdata.html" class="methodname">getData</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-binary.gettype.html" class="methodname">getType</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-binary.jsonserialize.html" class="methodname">jsonSerialize</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-binary.serialize.html" class="methodname">serialize</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-binary.tostring.html" class="methodname">__toString</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-binary.unserialize.html" class="methodname">unserialize</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$serialized</code></span>): <span class="type"><span class="type void">void</span></span></div>

   }</div>


  </div>
  

  <div class="section" id="mongodb-bson-binary.constants">
   <h2 class="title">预定义常量</h2>
   <dl>

    
     <dt id="mongodb-bson-binary.constants.type-generic"><strong><code>MongoDB\BSON\Binary::TYPE_GENERIC</code></strong></dt>

     <dd>

      <p class="para">Generic binary data.</p>
     </dd>

    

    
     <dt id="mongodb-bson-binary.constants.type-function"><strong><code>MongoDB\BSON\Binary::TYPE_FUNCTION</code></strong></dt>

     <dd>

      <p class="para">Function.</p>
     </dd>

    

    
     <dt id="mongodb-bson-binary.constants.type-old-binary"><strong><code>MongoDB\BSON\Binary::TYPE_OLD_BINARY</code></strong></dt>

     <dd>

      <p class="para">Generic binary data (deprecated in favor of <strong><code>MongoDB\BSON\Binary::TYPE_GENERIC</code></strong>).</p>
     </dd>

    

    
     <dt id="mongodb-bson-binary.constants.type-old-uuid"><strong><code>MongoDB\BSON\Binary::TYPE_OLD_UUID</code></strong></dt>

     <dd>

      <p class="para">Universally unique identifier (deprecated in favor of <strong><code>MongoDB\BSON\Binary::TYPE_UUID</code></strong>). When using this type, the Binary&#039;s data should be 16 bytes in length.</p>
      <p class="para">Historically, other drivers encoded values with this type based on their language conventions (e.g. varying endianness), which makes it non-portable. The PHP driver applies no special handling for encoding or decoding data with this type.</p>
     </dd>

    

    
     <dt id="mongodb-bson-binary.constants.type-uuid"><strong><code>MongoDB\BSON\Binary::TYPE_UUID</code></strong></dt>

     <dd>

      <p class="para">Universally unique identifier. When using this type, the Binary&#039;s data should be 16 bytes in length and encoded according to <a href="http://www.faqs.org/rfcs/rfc4122" class="link external">&raquo;&nbsp;RFC 4122</a>.</p>
     </dd>

    

    
     <dt id="mongodb-bson-binary.constants.type-md5"><strong><code>MongoDB\BSON\Binary::TYPE_MD5</code></strong></dt>

     <dd>

      <p class="para">MD5 hash. When using this type, the Binary&#039;s data should be 16 bytes in length.</p>
     </dd>

    

    
     <dt id="mongodb-bson-binary.constants.type-encrypted"><strong><code>MongoDB\BSON\Binary::TYPE_ENCRYPTED</code></strong></dt>

     <dd>

      <p class="para">Encrypted value. This subtype is used for client-side encryption.</p>
     </dd>

    

    
     <dt id="mongodb-bson-binary.constants.type-column"><strong><code>MongoDB\BSON\Binary::TYPE_COLUMN</code></strong></dt>

     <dd>

      <p class="para">Column data. This subtype is used for time-series collections.</p>
     </dd>

    

    
     <dt id="mongodb-bson-binary.constants.type-user-defined"><strong><code>MongoDB\BSON\Binary::TYPE_USER_DEFINED</code></strong></dt>

     <dd>

      <p class="para">User-defined type. While types between 0 and 127 are predefined or reserved, types between 128 and 255 are user-defined and may be used for anything.</p>
     </dd>

    

   </dl>

  </div>


  <div class="section">
   <h2 class="title">更新日志</h2>
   <p class="para">
    <table class="doctable informaltable">
     
      <thead>
       <tr>
        <th>版本</th>
        <th>说明</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td>PECL mongodb 1.12.0</td>
        <td>
         <p class="para">
          Implements <span class="interfacename"><a href="class.stringable.html" class="interfacename">Stringable</a></span> for PHP 8.0+.
         </p>
         <p class="para">
          Added <strong><code>MongoDB\BSON\Binary::TYPE_COLUMN</code></strong>.
         </p>
        </td>
       </tr>

       <tr>
        <td>PECL mongodb 1.7.0</td>
        <td>
         Added <strong><code>MongoDB\BSON\Binary::TYPE_ENCRYPTED</code></strong>.
        </td>
       </tr>

       <tr>
        <td>PECL mongodb 1.3.0</td>
        <td>
         Implements <span class="interfacename"><a href="class.mongodb-bson-binaryinterface.html" class="interfacename">MongoDB\BSON\BinaryInterface</a></span>.
        </td>
       </tr>

       <tr>
        <td>PECL mongodb 1.2.0</td>
        <td>
         Implements <span class="interfacename"><a href="class.serializable.html" class="interfacename">Serializable</a></span> and
         <span class="interfacename"><a href="class.jsonserializable.html" class="interfacename">JsonSerializable</a></span>.
        </td>
       </tr>

      </tbody>
     
    </table>

   </p>
  </div>

 </div>

 







 






 






 






 






 






 







<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="mongodb-bson-binary.construct.html">MongoDB\BSON\Binary::__construct</a> — Construct a new Binary</li><li><a href="mongodb-bson-binary.getdata.html">MongoDB\BSON\Binary::getData</a> — Returns the Binary's data</li><li><a href="mongodb-bson-binary.gettype.html">MongoDB\BSON\Binary::getType</a> — Returns the Binary's type</li><li><a href="mongodb-bson-binary.jsonserialize.html">MongoDB\BSON\Binary::jsonSerialize</a> — Returns a representation that can be converted to JSON</li><li><a href="mongodb-bson-binary.serialize.html">MongoDB\BSON\Binary::serialize</a> — Serialize a Binary</li><li><a href="mongodb-bson-binary.tostring.html">MongoDB\BSON\Binary::__toString</a> — Returns the Binary's data</li><li><a href="mongodb-bson-binary.unserialize.html">MongoDB\BSON\Binary::unserialize</a> — Unserialize a Binary</li></ul>
</div>
</div></div></body></html>